import axios from 'axios';
// 定义地址
//登录
let HTTP = axios.create({
	baseURL:'https://www.fastmock.site/mock/b72bf8a5ea3e583c1f356dc62f9acf5e/interface/',
})
// 用户登录
export const requestLogin = params => {
	return HTTP.get('ThingsGridTenant/tenants/login/'+params.account+'/'+params.checkPass).then(response => response.data)
}
// 用户修改密码
export const modifyPassword = params => {
	return HTTP.get('ThingsGridTenant/tenants/update/'+params.checkPass+'/'+params.newPwd+'/'+params.account).then(response => response.data)
}
// 获取数据
export const getUserAll = params => {
	if(params.api=="策略分析"){
		return HTTP.get('ThingsGridPolicy/policys/tenantId/'+params.tenantId).then(response => response.data)
	}else if(params.api=="设备影子"){
		console.log(params);
		return HTTP.get('ThingsGridShadow/shadow?thingsGrn='+params.thingsGrn).then(response => response.data)
	}else if(params.api=="设备管理"){	
		return HTTP.get('ThingsGridProduct/products?pageIndex='+params.pageIndex+'&filter='+params.content+'&pageSize='+params.pageSize+'&tenantId='+params.tenantId).then(response => response.data)		
	}else if(params.api=="应用列表"){	
		return HTTP.get('ThingsGridProduct/products?pageIndex='+params.pageIndex+'&filter='+params.content+'&pageSize='+params.pageSize+'&tenantId='+params.tenantId).then(response => response.data)		
	}
}
// 分页
export const getUserListPage = params => {
	if(params.api=="策略分析"){
		return HTTP.get('ThingsGridPolicy/policys/select?pageIndex='+params.pageIndex+'&filter='+params.content+'&pageSize='+params.pageSize+'&tenantId='+params.tenantId).then(response => response.data)
	}else if(params.api=="产品管理"){
		return HTTP.get('ThingsGridProduct/products/select?pageIndex='+params.pageIndex+'&filter='+params.content+'&pageSize='+params.pageSize+'&tenantId='+params.tenantId).then(response => response.data)
	}else if(params.api=="设备管理"){
		console.log(params);
		return HTTP.get('ThingsGridProduct/things/select?pageIndex='+params.pageIndex+'&filter='+params.content+'&pageSize='+params.pageSize+'&tenantId='+params.tenantId+'&productGrn='+params.productGrn).then(response => response.data)
	}else if(params.api=="产品固件"){
		console.log(params);
		return HTTP.get('ThingsGridProduct/things/select?pageIndex='+params.pageIndex+'&filter='+params.content+'&pageSize='+params.pageSize+'&tenantId='+params.tenantId+'&productGrn='+params.productGrn).then(response => response.data)
	}		
}
// 新增
export const addUser = params => {
	if(params.api=="策略分析"){
		return HTTP.post('ThingsGridPolicy/policys/add',params).then(response => response.data)
	}else if(params.api=="产品管理"){
		return HTTP.post('ThingsGridProduct/products/add',params).then(response => response.data)
	}else if(params.api=="设备管理"){
		return HTTP.post('ThingsGridProduct/things/add',params).then(response => response.data)
	}else if(params.api=="产品固件"){
		return HTTP.post('ThingsGridProduct/things/add',params).then(response => response.data)
	}else if(params.api=="消息测试"){
		return HTTP.post('/messageTest',params).then(response => response.data)
	}	
}
// 删除
export const removeUser = params => {
	if(params.api=="策略分析"){
		return HTTP.get('ThingsGridPolicy/policys/delete/'+params.id).then(response => response.data)
	}else if(params.api=="产品管理"){
		return HTTP.get('ThingsGridProduct/products/delete/'+params.id).then(response => response.data)
	}else if(params.api=="设备管理"){
		return HTTP.get('ThingsGridProduct/things/delete/'+params.tenantId+'/'+params.thingGrn).then(response => response.data)
	}else if(params.api=="产品固件"){
		return HTTP.get('ThingsGridProduct/things/delete/'+params.tenantId+'/'+params.thingGrn).then(response => response.data)
	}
}
// 修改
export const editUser = params => {
	if(params.api=="策略分析"){
		return HTTP.post('ThingsGridPolicy/policys/update',params).then(response => response.data)
	}else if(params.api=="产品管理"){
		return HTTP.post('ThingsGridProduct/products/update',params).then(response => response.data)
	}else if(params.api=="设备管理"){
		return HTTP.post('ThingsGridProduct/things/update',params).then(response => response.data)
	}else if(params.api=="产品固件"){
		return HTTP.post('ThingsGridProduct/things/update',params).then(response => response.data)
	}
}
		
// 批量删除
export const batchRemoveUser = params => {
	if(params.api=="设备管理"){
		return HTTP.get('ThingsGridProduct/things/delete/many/'+params.tenantId+'/'+params.thingGrn).then(response => response.data)
	}
}
// 策略绑定
export const bangUser = params => {
	if(params.api=="产品管理"){
		return HTTP.get('ThingsGridProduct/products/update/'+params.policy+'/'+params.productId).then(response => response.data)
	}
}
